package com.xoa.controller.hr;

import com.xoa.model.hr.HrphotoWithBLOBs;
import com.xoa.service.hr.HrphotoService;
import com.xoa.util.CookiesUtil;
import com.xoa.util.ToJson;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.common.wrapper.BaseWrapper;
import com.xoa.util.dataSource.ContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

/**
 * @author 左春晖
 * @date 2018/7/3 18:16
 * @desc
 */
@Controller
@RequestMapping("/hr/manage")
public class HrphotoController {

    @Resource
    HrphotoService hrphotoService;

    //添加
    @ResponseBody
    @RequestMapping("/addHrphotos")//  /hr/manage/addHrphotos
    public ToJson addHrphotos(HttpServletRequest request, HrphotoWithBLOBs hrphotoWithBLOBs){
        return hrphotoService.addHrphoto(request,hrphotoWithBLOBs);
    }

    //修改
    @ResponseBody
    @RequestMapping("/upHrphotos")  //  /hr/manage/upHrphotos
    public ToJson upHrphotos(HrphotoWithBLOBs hrphotoWithBLOBs){
        return hrphotoService.upHrphoto(hrphotoWithBLOBs);
    }

    //删除
    @ResponseBody
    @RequestMapping("/deleteHrphotos")  //  /hr/manage/deleteHrphotos
    public ToJson deleteHrphotos(@RequestParam("ids[]") String[] ids){
        return hrphotoService.deleteHrphoto(ids);
    }


    //查询  导出
    @ResponseBody
    @RequestMapping("/selectHrphotos")  //  /hr/manage/selectHrphotos
    public ToJson<HrphotoWithBLOBs> selectHrphotos(HttpServletResponse response, HttpServletRequest request, HrphotoWithBLOBs hrphotoWithBLOBs, Integer page, Integer pageSize, boolean useFlag, String export)throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException  {
        return hrphotoService.selectHrphoto(response,request,hrphotoWithBLOBs,page,pageSize,useFlag,export);
    }

    //导入
    @ResponseBody
    @RequestMapping("/imports") //  /hr/manage/imports
    public ToJson<HrphotoWithBLOBs> imports(HttpServletRequest request, HttpServletResponse response, MultipartFile file) {
        return hrphotoService.imports(request,response,file);
    }

    //下拉框获取
    @RequestMapping("/getHrCodes")
    @ResponseBody
    public BaseWrapper getHrCodes(String type) {
        return hrphotoService.getHrCodes(type);
    }



    //主页面
    @RequestMapping("/staff_license") //    /hrPhoto/navigationBar   /hr/manage/staff_license
    public String photoManagement(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/hrPhoto/HrPhotoBar";
    }

    //详情页
    @RequestMapping("/photoDetail")  //     /hr/manage/photoDetail
    public String photoDetail(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/hrPhoto/HrPhotoDetail";
    }

    //导入页
    @RequestMapping("/photoExport")   //    /hr/manage/photoExport
    public String photoExport(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/hrPhoto/HrPhotoImport";
    }

    //管理页面
    @RequestMapping("/photoManage")   //    /hr/manage/photoManage
    public String photoManage(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/hrPhoto/HrPhotoManager";
    }

    //新建页面
    @RequestMapping("/photoNewedit")   //    /hr/manage//photoNewedit
    public String photoNewedit(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/hrPhoto/HrPhotoNew";
    }

    //查询页面
    @RequestMapping("/photoQuery")   //     /hr/manage//photoQuery
    public String photoQuery(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/hrPhoto/HrPhotoQuery";
    }




    }
